import { api, API_TSL_FRONTEND } from "../boot/axios";

export async function getPrintLabelStatusReport(param, currentPage, rowPerPage, sortCol) {
  console.log("param", param);
  const res = await api.get(API_TSL_FRONTEND + "/report/PrintStatusView/", {
    params: { 
        gold_print_status: param,
        page: currentPage,
        rows_per_page: rowPerPage,
        sort_seq: sortCol
     },
  });
  if (res.data) {
    return res.data;
  }
}


export async function exportPrintLabelStatusReport(param) {
  console.log("param", param);
  const res = await api.get(API_TSL_FRONTEND + "/report/PrintStatusView/" + "list_export_csv/", {
    params: { 
        gold_print_status: param,
     },
  });
  return res
}


export async function getLeadtimeReport(filter, account_id, currentPage, rowPerPage, sortCol) {
  const res = await api.get(API_TSL_FRONTEND + "/report/LeadTimeReportView/", {
    params: {
      order_no: filter.orderNo,
      source: filter.source,
      flow: filter.flow,
      dept: filter.dept,
      account_id: account_id,
      page: currentPage,
      rows_per_page: rowPerPage,
      sort_seq: sortCol
    },
  });
  if (res.data) {
    return res.data;
  }
}

export async function getLeadtimeReportOptionList() {
    const res = await api.get(API_TSL_FRONTEND + "/report/LeadTimeReportView/get_option_list");
    if (res.data) {
      return res.data;
    }
  }

export async function getQCTransactionReport(searchReq, accId, currentPage, rowPerPage, sortCol){
    const res = await api.post(
    API_TSL_FRONTEND + "/report/QCReportView/" + "qcTransactionReport/?page=" + currentPage,
    {
        account_pk: accId,
        deliverDate: searchReq.deliverDate,
        completeDate: searchReq.completeDate,
        deliverDateEnd: searchReq.deliverDateEnd,
        completeDateEnd: searchReq.completeDateEnd,
        source: searchReq.source,
        dept_id: searchReq.dept,
        orderNo: searchReq.orderNo,
        workerCode: searchReq.workerCode,
        checkerCode: searchReq.checkerCode,
        page: currentPage,
        rows_per_page: rowPerPage,
        sort_seq: sortCol
    }
    );
    if (res.data){
        return res.data
    }
}


export async function exportQCTransactionReport(searchReq, accId){
  console.log(accId);
  console.log(searchReq);
  const res = await api.get(API_TSL_FRONTEND + "/report/QCReportView/" + "qcTransactionExportCsv/", {
    params: { 
      account_pk: accId,
      deliverDate: searchReq.deliverDate || '',
      completeDate: searchReq.completeDate || '',
      deliverDateEnd: searchReq.deliverDateEnd || '',
      completeDateEnd: searchReq.completeDateEnd || '',
      source: searchReq.source || '',
      dept_id: searchReq.dept || '',
      orderNo: searchReq.orderNo || '',
      workerCode: searchReq.workerCode || '',
      checkerCode: searchReq.checkerCode || '',
     },
  });
  return res
}

export async function exportLeadtimeReport(filter, account_id) {
  const res = await api.get(API_TSL_FRONTEND + "/report/LeadTimeReportView/"+"list_export_csv/", {
    params: {
      order_no: filter.orderNo,
      source: filter.source,
      flow: filter.flow,
      dept: filter.dept,
      account_id: account_id,
      // page: currentPage,
      // rows_per_page: rowPerPage,
      // sort_seq: sortCol
    },
  });

  return res;
}



export async function exportWorkerReportResult(reportType,
  staffCode,
  userCode,
  goldType,
  dateFrom,
  dateTo){
  const res = await api.get(API_TSL_FRONTEND + "/report/WorkerReportView/" + "get_report_result_export_csv/", {
    params: { 
        report_type: reportType,
        staffcode: staffCode,
        usercode: userCode,
        gold_type: goldType,
        date_from: dateFrom,
        date_to: dateTo,
        
     },
  });
  return res
}



export async function exportFGarticle2Excel(params){
  const url = API_TSL_FRONTEND + '/uploadRoutingTable'+'/searchFGArticleExportExcel/'
  const res = await api({
    method:'get',
    responseType:'blob',
    url,
    params
  })
  return res
}



export async function exportQCStockReport(reportType, accId){
  console.log("exportQCStockReport")
  console.log(reportType, accId)
  const res = await api.get(API_TSL_FRONTEND + "/report/QCInventoryReportView/" + "qcInventoryExportCsv/", {
    params: { 
        report_type: reportType,
        account_id: accId,
     },
  });
  return res
}
